<?php
	require_once('preheader.php');
	#the code for the class
	include('ajaxCRUD.class.php');
    #this one line of code is how you implement the class
    ########################################################
    ##

    $tbl = new ajaxCRUD("Character", "char", "char_id", "");

    ##
    ########################################################

  
    #i can define a relationship to another table
    #the 1st field is the fk in the table, the 2nd is the second table, the 3rd is the pk in the second table, the 4th is field i want to retrieve as the dropdown value
    #http://ajaxcrud.com/api/index.php?id=defineRelationship
    $tbl->defineRelationship("user", "users", "user", "user");
    $tbl->defineRelationship("left_ring", "items", "item", "item_type");
    $tbl->defineRelationship("right_ring", "items", "item", "item_type");
    $tbl->defineRelationship("left_hand", "items", "item", "item_type");
    $tbl->defineRelationship("right_hand", "items", "item", "item_type");
    $tbl->defineRelationship("neck", "items", "item", "item_type");
    $tbl->defineRelationship("head", "items", "item", "item_type");
    $tbl->defineRelationship("face", "items", "item", "item_type");
    $tbl->defineRelationship("left_ear", "items", "item", "item_type");
    $tbl->defineRelationship("right_ear", "items", "item", "item_type");
    $tbl->defineRelationship("feet", "items", "item", "item_type");
    $tbl->defineRelationship("legs", "items", "item", "item_type");
    $tbl->defineRelationship("chest", "items", "item", "item_type");
    $tbl->defineRelationship("hands", "items", "item", "item_type");
    $tbl->defineRelationship("arms", "items", "item", "item_type");
    $tbl->defineRelationship("back", "items", "item", "item_type");
    $tbl->defineRelationship("waist", "items", "item", "item_type");
    $tbl->defineRelationship("room", "rooms", "room", "name");
    
    #i don't want to visually show the primary key in the table
    //$tbl->omitPrimaryKey();

    #i want to give the heading titles something more meaningful
    $tbl->displayAs("user", "User");
    $tbl->displayAs("char_id", "Character");
    $tbl->displayAs("description", "Description");
    $tbl->displayAs("gender", "Gender");
    $tbl->displayAs("strenght", "Str");
    $tbl->displayAs("dexterity", "Dex");
    $tbl->displayAs("vitality", "Vit");
    $tbl->displayAs("intelligence", "Int");
    $tbl->displayAs("left_ring", "Left Ring");
    $tbl->displayAs("right_ring", "Right Ring");
    $tbl->displayAs("left_hand", "Left Hand");
    $tbl->displayAs("right_hand", "Right Hand");
    $tbl->displayAs("neck", "Neck");
    $tbl->displayAs("head", "Head");
    $tbl->displayAs("face", "Face");
    $tbl->displayAs("left_ear", "Left Ear");
    $tbl->displayAs("right_ear", "Right Ear");
    $tbl->displayAs("feet", "Feet");
    $tbl->displayAs("legs", "Legs");
    $tbl->displayAs("chest", "Chest");
    $tbl->displayAs("hands", "Hands");
    $tbl->displayAs("arms", "Arms");
    $tbl->displayAs("back", "Back");
    $tbl->displayAs("waist", "Waist");
    $tbl->displayAs("experience", "XP");
    $tbl->displayAs("life", "HP");
    $tbl->displayAs("mana", "Mana");
    $tbl->displayAs("room", "Room");

	#set the textarea height of the longer field (for editing/adding)
    #http://ajaxcrud.com/api/index.php?id=setTextareaHeight
    $tbl->setTextareaHeight('description', 200);

    #i could omit a field if I wanted
    #http://ajaxcrud.com/api/index.php?id=omitField
    $tbl->omitField("refresh");
    $tbl->omitField("updated");
    $tbl->omitField("left_ring");
    $tbl->omitField("right_ring");
    $tbl->omitField("left_hand");
    $tbl->omitField("right_hand");
    $tbl->omitField("neck");
    $tbl->omitField("head");
    $tbl->omitField("face");
    $tbl->omitField("left_ear");
    $tbl->omitField("right_ear");
    $tbl->omitField("feet");
    $tbl->omitField("legs");
    $tbl->omitField("chest");
    $tbl->omitField("hands");
    $tbl->omitField("arms");
    $tbl->omitField("back");
    $tbl->omitField("waist");
    
    #i could omit a field from being on the add form if I wanted
    $tbl->omitAddField("refresh");
    $tbl->omitAddField("updated");
    $tbl->omitAddField("left_ring");
    $tbl->omitAddField("right_ring");
    $tbl->omitAddField("left_hand");
    $tbl->omitAddField("right_hand");
    $tbl->omitAddField("neck");
    $tbl->omitAddField("head");
    $tbl->omitAddField("face");
    $tbl->omitAddField("left_ear");
    $tbl->omitAddField("right_ear");
    $tbl->omitAddField("feet");
    $tbl->omitAddField("legs");
    $tbl->omitAddField("chest");
    $tbl->omitAddField("hands");
    $tbl->omitAddField("arms");
    $tbl->omitAddField("back");
    $tbl->omitAddField("waist");

    #i could disallow editing for certain, individual fields
   // $tbl->disallowEdit('behaviour');
	
    #i could set a field to accept file uploads (the filename is stored) if wanted
    //$tbl->setFileUpload("fldField2", "uploads/");

    #i can have a field automatically populate with a certain value (eg the current timestamp)
    //$tbl->addValueOnInsert("fldField1", "NOW()");

    #i can use a where field to better-filter my table
    //$tbl->addWhereClause("WHERE (fldField1 = 'test'");

    #i can order my table by whatever i want
    //$tbl->addOrderBy("ORDER BY name ASC");

    #i can set certain fields to only allow certain values
    #http://ajaxcrud.com/api/index.php?id=defineAllowableValues
    //$allowableValues = array("Allowable Value 1", "Allowable Value2", "Dropdown Value", "CRUD");
    //$tbl->defineAllowableValues("fldCertainFields", $allowableValues);

    #i can disallow deleting of rows from the table
    #http://ajaxcrud.com/api/index.php?id=disallowDelete
    $tbl->disallowDelete();

    #i can disallow adding rows to the table
    #http://ajaxcrud.com/api/index.php?id=disallowAdd
    //$tbl->disallowAdd();

    #i can add a button that performs some action deleting of rows for the entire table
    #http://ajaxcrud.com/api/index.php?id=addButtonToRow
    //$tbl->addButtonToRow("Add", "add_item.php", "all");

    #set the number of rows to display (per page)
    $tbl->setLimit(30);

	#set a filter box at the top of the table
    $tbl->addAjaxFilterBox('char_id');
    $tbl->addAjaxFilterBox('user');

    #if really desired, a filter box can be used for all fields
    //$tbl->addAjaxFilterBoxAllFields();

    #i can set the size of the filter box
    //$tbl->setAjaxFilterBoxSize('fldField1', 3);

	#i can format the data in cells however I want with formatFieldWithFunction
	#this is arguably one of the most important (visual) functions
	//$tbl->formatFieldWithFunction('password', 'hashIt');

	$tbl->onAddSpecifyPrimaryKey();

	include('header.php');	

	#actually show the table	
	$tbl->showTable();
	
	include('footer.php');

	#my self-defined functions used for formatFieldWithFunction
	/*function hashIt($val){
		return sha1($val);
	}*/

	

?>
